<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>OSP&nbsp;-&nbsp;后台管理平台</title>
    <link rel="stylesheet" type="text/css" href="static/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="static/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="static/easyui/ext-themes/default/ext-easyui.css">
    <link rel="stylesheet" type="text/css" href="static/easyui/ext-themes/ext-icon.css">
    <link rel="stylesheet" type="text/css" href="static/easyui/plugins/portal/portal.css">
    <link rel="stylesheet" type="text/css" href="static/font-awesome/css/font-awesome.css">
    <link rel="stylesheet" type="text/css" href="static/style.css">
    <script type="text/javascript" src="static/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="static/easyui/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="static/easyui/plugins/portal/jquery.portal.js"></script>
</head>
<body class="easyui-layout">
<div data-options="region:'north'" style="padding: 5px;">
    <img src="static/images/logo.png" height="50px">
    <span class="fr" style="margin-top: 15px;">
        <a href="#" class="easyui-menubutton" data-options="menu:'#user_tools'"><span id="USER"></span></a>
        <div id="user_tools" style="width:100px;">
            <div><a href="javascript:loadTab('用户设置','../site-users/config.action');">用户设置</a></div>
            <div class="menu-sep"></div>
            <div><a href="../site-default/logout.action">退出</a></div>
	    </div>
    </span>
</div>
<div data-options="region:'west',split:true" title="" style="width:160px;">
    <div class="easyui-layout" data-options="fit:true,doSize:false" border="false">
        <div data-options="region:'center'" border="false">
            <ul class="easyui-tree" id="menu-tree"></ul>
        </div>
    </div>
</div>
<div data-options="region:'center'">
    <div class="easyui-tabs" id="tabs_content" data-options="fit:true,border:false,plain:true">
    </div>
</div>
<script>
    $(function () {
        getUser();
        addPortal();
    });

    function getUser() {
        //获取用户基本信息
        $.get('site-default/getUser.action', null, function (res) {
            $("#USER").html(res);
        });
    }

    function addPortal() {
        $('#tabs_content').tabs('add', {
            title: "后台首页",
            href: "site-default/portal.action"
        });
    }

    /*默认的菜单树*/
    $('#menu-tree').tree({
        url: 'site-default/getmenu.action',
        method: 'get',
        onClick: function (node) {
            if (node.attributes.menuurl != "" && node.attributes.menuurl != null) {
                addTab(node);
            } else {
                //展开当前这个节点
                $('#menu-tree').tree("expand", $('#menu-tree').tree('find', node.id).target);
            }
        }
    });
    function addTab(node) {
        var title = node.text;
        var exist = $('#tabs_content').tabs('exists', title);
        if (exist) {
            $('#tabs_content').tabs('select', title);
        } else {
            //添加一个TAB页面
            $('#tabs_content').tabs('add', {
                title: title,
                href: node.attributes.menuurl,
                closable: true
            });
        }
        RefreshTab($('#tabs_content').tabs('getSelected'));
    }
    function loadTab(title, href) {
        var exist = $('#tabs_content').tabs('exists', title);
        if (exist) {
            $('#tabs_content').tabs('select', title);
        } else {
            //添加一个TAB页面
            $('#tabs_content').tabs('add', {
                title: title,
                href: href,
                closable: true
            });
        }
        RefreshTab($('#tabs_content').tabs('getSelected'));
    }
    //刷新当前标签Tabs
    function RefreshTab(currentTab) {
        var url = $(currentTab.panel('options')).attr('href');
        $('#tabs_content').tabs('update', {
            tab: currentTab,
            options: {
                href: url
            }
        });
        currentTab.panel('refresh');
    }
    function loadCurrent(title,href) {
        var tab = $('#tabs_content').tabs('getSelected');
        $('#tabs_content').tabs('update', {
            tab:tab,
            options: {
                title: title,
                href:href
            }
        });
        tab.panel('refresh');
    }
</script>
</body>
</html>